﻿using MyDay13.Context;
using MyDay13.IRepostitype;
using MyDay13.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyDay13Repostitype
{
    public class UserRepostitype : IUserRepostitype
    {
        Day13Context db;
        public UserRepostitype(Day13Context dbs)
        {
            db = dbs;
        }

        public int Login(string name, string pwd)
        {
            var flag = 0;
            var list = db.D13User.ToList().Where(x => x.Account == name && x.Pwd == pwd).FirstOrDefault();
            if (list!=null)
            {
                flag = list.UId;
            }
            return flag;
        }

        public int UserAdd(D13User d13User)
        {
            db.D13User.Add(d13User);
            return db.SaveChanges();
        }

        public int UserDel(string ids)
        {
            var list = db.D13User.ToList().Where(x => ids.Contains(x.UId.ToString())).ToList();
            db.D13User.RemoveRange(list);
            return db.SaveChanges();
        }

        public List<D13User> UserShow()
        {
            var list = db.D13User.ToList();
            return list;
        }

        public int UserUpt(D13User d13User)
        {
            db.Entry(d13User).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return db.SaveChanges();
        }
    }
}
